package com.coding.service.impl;

import com.coding.base.pojo.BaseModel;
import com.coding.dao.TaskDao;
import com.coding.pojo.Task;
import com.coding.service.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auther wangchenghao
 * @date 2020/7/26
 **/

@Service
public class TaskImpl implements TaskService {
    @Autowired
    TaskDao taskDao;

    @Override
    public void gettaskbyid(int task_id, BaseModel baseModel) throws Exception {
        Task task = taskDao.selectByPrimaryKey(task_id);
        if (task != null) {
            baseModel.setSucceed("获取任务成功", task);
        } else {
            baseModel.setFailure("获取任务失败");
        }
    }

    /**按条件获得任务列表
     * @param task
     * @param baseModel
     * @throws Exception
     */
    @Override
    public void gettasklist(Task task, BaseModel baseModel) throws Exception {
        List<Task> taskList= taskDao.queryAlllist(task);
        if (taskList.size() > 0) {
            baseModel.setSucceed("获得任务列表成功", taskList);
        } else {
            baseModel.setFailure("获得任务列表失败");
        }
    }


    @Override
    public void addnewlist(Task task, BaseModel baseModel) throws Exception {
        taskDao.insertSelective(task);
        if (task.getTask_id() != 0) {
            baseModel.setSucceed("新增任务成功", task);
        } else {
            baseModel.setFailure("新增任务失败");
        }
    }
}
